package com.yzq.model.vo;

import com.yzq.model.entity.User;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class UserVO implements Serializable {
    private static final long serialVersionUID = -3533175959819359581L;
    /**
     * id
     */
    private Long id;

    /**
     * 账号
     */
    private String userAccount;

    /**
     * 用户昵称
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 用户简介
     */
    private String userProfile;

    /**
     * 用户角色：user/admin
     */
    private String userRole;

    /**
     * 用户电话号码
     */
    private String phone;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 创建时间
     */
    private Date createTime;

    public static UserVO toVO(User user) {
        if (user == null) {
            return null;
        }
        UserVO userVO = new UserVO();
        userVO.setId(user.getId());
        userVO.setUserAccount(user.getUserAccount());
        userVO.setUserName(user.getUserName());
        userVO.setUserAvatar(user.getUserAvatar());
        userVO.setUserProfile(user.getUserProfile());
        userVO.setUserRole(user.getUserRole());
        userVO.setPhone(user.getPhone());
        userVO.setEmail(user.getEmail());
        userVO.setCreateTime(user.getCreateTime());
        return userVO;
    }

    public static User toEntity(UserVO userVO) {
        if (userVO == null) {
            return null;
        }
        User user = new User();
        user.setId(userVO.getId());
        user.setUserAccount(userVO.getUserAccount());
        user.setUserName(userVO.getUserName());
        user.setUserAvatar(userVO.getUserAvatar());
        user.setUserProfile(userVO.getUserProfile());
        user.setUserRole(userVO.getUserRole());
        user.setPhone(userVO.getPhone());
        user.setEmail(userVO.getEmail());
        user.setCreateTime(userVO.getCreateTime());
        return user;
    }


}
